<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>05-调整窗口大小事件</title>
  <style>
    div {
      width: 200px;
      height: 200px;
      background-color: pink;
    }
  </style>
</head>

<body>
  <script>
    window.addEventListener('load', function () {
      var div = document.querySelector('div');
      // 1. resize: 只要浏览器像素发生变化时触发此事件
      window.addEventListener('resize', function () {
        // a. innerWidth: 当前浏览器宽度
        // b. innerHeight: 当前浏览器高度
        console.log('width: ', window.innerWidth);
        console.log('height', window.innerHeight);
        // 当前浏览器宽度小于800时, 隐藏div，否则显示
        if (window.innerWidth <= 800) {
          div.style.display = 'none';
        } else {
          div.style.display = 'block';
        }

      })
    })
  </script>
  <div></div>
</body>

</html>